﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using ATSBLL;
using ATSModel;
using System.Collections.Generic; 

/// <summary>
///ServiceForAirtightness 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class ServiceForAirtightness : System.Web.Services.WebService
{
    private Airtightness a;
    private AirtightnessConfig ac;
    private TProductType p;
    private TRoleInfo tInfo;
    public Role tRole;
    public ServiceForAirtightness()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 

        a = new Airtightness(); //气密 
        ac = new AirtightnessConfig();//气密测试配置
        p = new TProductType(); //产品类型
        tInfo = new TRoleInfo();
        tRole = new Role();//用户信息
     
    }
     

    [WebMethod(Description = "判断产品类型是否合法")]
    public bool IsValidProductTypeID(string productTypeID)
    {
        return !string.IsNullOrEmpty(p.LoadEntity(productTypeID).ProductTypeID);
    }

    [WebMethod(Description = "判断产品类型相应通道的气密信息是否登记")]
    public bool HasValidProductType_AirtightnessInfo(string productTypeID, int channelNO)
    {
        return !string.IsNullOrEmpty(ac.Airtightness_GetbyPIDCHNO(productTypeID, channelNO).ProductTypeID);
    }

    [WebMethod(Description = "获取此产品类型气密信息中的规格值")]
    public AirtightnessConfigInfo GetSpecValuebyPID(string productTypeID, int channelNO)
    {
        return ac.Airtightness_GetbyPIDCHNO(productTypeID, channelNO);
    } 

    [WebMethod(Description = "上传气密数据")] 
    public bool TestData_Upload(AirtightnessInfo ai)
    { 
        return a.Insert(ai);  
    }

    [WebMethod(Description = "根据序列号查询气密数据")]
    public List<AirtightnessInfo> GetAirtightness_bySN(string productSN)
    {
        return (List<AirtightnessInfo>)a.Airtightness_SelectbySN(productSN);
    }


    [WebMethod(Description = "用户登录账号验证")]
    public bool AuthenticateUser(string UserID, string Pwd)
    {
        tInfo = tRole.GetForUser(UserID);
        if (tInfo == null)
        {
            return false;
        }
        if (tInfo.Password == Pwd)
        {
            return true;
        }
        return false; 
    }

    [WebMethod(Description = "获取用户权限")]
    public string AuthorizeUser(string UserID)
    { 
        tInfo = tRole.GetForUser(UserID);
        return tInfo.Power;
    }

}

